package question1.file;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.stream.Stream;

public class DiGui {
    public static void main(String[] args) {
        String path="C:\\Users\\29022\\Documents\\XiaoMiNet\\Upupoo\\Docker\\config\\文件夹\\新建文件夹\\作业及资料\\作业";
        File file = new File(path);
        ArrayList<File> files1 = new ArrayList<>();
        ArrayList<File> files2 = new ArrayList<>();
        HashMap<String, Integer> hm = new HashMap<>();
        diGui(file,files1,files2);
        System.out.println(files1);
        System.out.println(files2);
        for (File file1 : files1) {
            String[] split = file1.getName().split("\\.");
            if (split.length>1){
                if (hm.containsKey(split[split.length-1])){
                    hm.put(split[split.length-1],hm.get(split[split.length-1])+1);
                }else{
                    hm.put(split[split.length-1],1);
                }
            }
        }
        System.out.println(hm);
    }

    private static void diGui(File file, ArrayList<File> files1, ArrayList<File> files2) {
       if (file!=null){
           for (File Files : file.listFiles()) {
               if (Files!=null){
                   if (Files.isFile()){
                       files1.add(Files);
                   }else{
                       files2.add(Files);
                       diGui(Files,files1,files2);
                   }
               }
           }
       }
    }
}
